package BehaviorDesignPattern.MementoPattern;

public class TestMementoPattern {

    public static void main(String[] args) {
        // 创建发起人对象
        Originator originator = new Originator();

        // 创建负责人对象
        Caretaker caretaker = new Caretaker();

        // 设置初始状态
        originator.setState("忘不掉");
        System.out.println("Initial State: " + originator.getState());

        // 保存当前状态到备忘录
        caretaker.saveMemento(originator.saveToMemento());

        // 修改状态
        originator.setState("不知道，也许");
        System.out.println("Modified State: " + originator.getState());

        // 从备忘录恢复状态
        originator.restoreFromMemento(caretaker.retrieveMemento());
        System.out.println("Restored State: " + originator.getState());
    }
}
